﻿using Iworld.Basis.Model;
using Iworld.Author.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Game.Model
{
    /// <summary>
    /// 牌局的投注信息
    /// </summary>
    public class Betting : RecordingTimeModelBase
    {

        /// <summary>
        /// 赔率
        /// </summary>
        private static Dictionary<PokerColor,double> Odds = new Dictionary<PokerColor,double>(); 

        static Betting()
        {
            Odds.Add(PokerColor.黑桃, 3.8);
            Odds.Add(PokerColor.红桃, 3.8);
            Odds.Add(PokerColor.梅花, 4);
            Odds.Add(PokerColor.方块, 4);
            Odds.Add(PokerColor.王, 20);
        }

        public Betting() {  }

        public Betting(Iworld.Author.Model.Author owner, GameRound gameRound,string golds) 
        {
        }

        /// <summary>
        /// 投注人
        /// </summary>
        public virtual Iworld.Author.Model.Author Owner { get; set; }

        /// <summary>
        /// 投注局
        /// </summary>
        public virtual GameRound GameRound { get; set; }

        /// <summary>
        /// 投注的金币集,10,23,45,67,50
        /// </summary>
        public string Golds { get; set; }
        
        /// <summary>
        /// 当前状态
        /// </summary>
        public BettingStatus Status { get; set; }

        /// <summary>
        /// 中奖分数
        /// </summary>
        public double Bonus { get; set; }

        /// <summary>
        /// 反奖
        /// </summary>
        /// <param name="round"></param>
        public void Pay(GameRound round)
        {
            if (!round.IsLottery) return;
            this.Status = BettingStatus.未中奖;
            if (Golds == null) return;
            string[] values = Golds.Split(new Char[]{ ',' });
            if (values.Count() < 5) return;
            //黑桃
            double spade = double.Parse(values[0]);
            //红桃
            double heart = double.Parse(values[1]);
            //梅花
            double club = double.Parse(values[2]);
            //方块
            double diamond = double.Parse(values[3]);
            //王
            double king = double.Parse(values[4]);

            Dictionary<PokerColor, double> betting = new Dictionary<PokerColor, double>();
            betting.Add(PokerColor.黑桃, spade);
            betting.Add(PokerColor.红桃, heart);
            betting.Add(PokerColor.梅花, club);
            betting.Add(PokerColor.方块, diamond);
            betting.Add(PokerColor.王, king);

            PokerColor color = round.PokerColor;
            double betWinValue = betting[color];
            if (betWinValue >= 0)
            {
               double odds =  Odds[color];
               this.Bonus = betWinValue * odds;
               if(color == PokerColor.王)
               {
                   this.Bonus += (spade + heart + club + diamond + king);
               }
               this.Bonus = Math.Round(this.Bonus, 2);
               this.Status = BettingStatus.中奖;
            }
 
        }
    }
}
